import os
from typing import List, Optional
from pydantic import BaseSettings

class Settings(BaseSettings):
    API_V1_STR: str = "/api/v1"
    PROJECT_NAME: str = "爬虫管理系统"
    
    # 数据库配置
    DATABASE_URL: str = "sqlite:///./spider_manage.db"
    
    # 文件存储路径
    BASE_DIR: str = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    SPIDERS_DIR: str = os.path.join(BASE_DIR, "spiders")
    LOGS_DIR: str = os.path.join(BASE_DIR, "logs")
    
    # Docker配置
    DOCKER_BASE_IMAGE: str = "python:3.9-slim"
    DOCKER_NETWORK: Optional[str] = None
    
    # CORS设置
    CORS_ORIGINS: List[str] = ["*"]
    SCHEDULE_WORKERS=5
    class Config:
        env_file = ".env"
        case_sensitive = True

settings = Settings()

# 确保必要的目录存在
os.makedirs(settings.SPIDERS_DIR, exist_ok=True)
os.makedirs(settings.LOGS_DIR, exist_ok=True)